home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Almathera Ten Pack 3: CDPD 3
/
Almathera Ten on Ten - Disc 3: CDPD3.iso
/
scope
/
051-075
/
scopedisk62
/
graf
/
graf.doc
< prev
next >
Wrap
Text File
|
1995-03-19
|
8KB
|
184 lines
Graf - Bill Nickerson
==============================
History.
========
Graf is a program originally meant for graphing multiple functions of one
variable entered from the keyboard. A calculator mode was so easy to add
that it is included also.
The inspiration for graf came from the graph sketching classes we had in
intro calculus. I wanted a nice and quick way of checking my work. Also, since
I was marking and teaching a night class for a translators, I wanted a sample
lexical analyzer and expression parser. Besides, I hadn't really done anything
majorly graphic with my Amiga since I got it a couple years ago and this just
happen to be a good excuse.
Execution.
==========
Graf must be run from some sort of cli. If no arguments are given, then you
are popped into graphing mode, indicated by a window appearing in the upper
left hand corner of the screen. If you give it the solitary argument "calc",
then a title line is output and you are in calculator mode, indicated by the
number 1 in square brackets at the left side of the current line. If any
other arguments are given, a usage message is displayed and you get the cli
back.
Functions Available.
====================
Before the operation of the program is explained, a list of functions would
probably be useful. The parser is really quite powerful and does a lot of
error checking for you. Errors that are made during parsing are indicated
and errors that occur during evaluation (like taking the square root of -1)
are either pointed out or ignored, depending on which mode you happen to be
in. Anyhow, a list of functions....
--**-----------
NOTE: arguments to the trig functions must be given in radians.
--**-----------
-x - negation of x.
acos(x) - arccos of x.
asin(x) - arcsin of x.
atan(x) - arctan of x.
cosh(x) - hyperbolic cos of x.
sinh(x) - hyperbolic sin of x.
tanh(x) - hyperbolic tan of x.
cos(x) - cos of x.
sin(x) - sin of x.
tan(x) - tan of x.
exp(x) - e to power x.
ln(x) - natural log of x.
log(x) - log base 10 of x.
sqrt(x) - square root of x.
<<(x) - floor of x.
>>(x) - ceiling of x.
|(x) - absolute value of x.
!(x) - factorial of floor of x.
x * y - product of x and y.
x / y - division of x by y.
x % y - modulus of x by y.
x ^ y - x to power of y.
x + y - sum of x and y.
x - y - difference of x and y.
x : y - sum of integers between floor of x and y.
Parentheses work the way they usually do, the usual limits on boundaries apply,
and precedence is as usual. For the most part, the functions above are listed
according to precedence. Summation is a bit weird, but examples should suffice.
1:3+2:5 is (((1:3)+2):5) == ((6+2):5) == (8:5) == 26
(1:3)+(2:5) is ((1:3)+(2:5)) == (6 + 14) == 20
1:3*2:5 is ((1:(3*2)):5) == ((1:6):5) == 21:5 == 221
--**-----------
As a side note, how many have noticed that a few of the IEEE math routines
do not give errors where there should be some? For example, tan of 90 degrees
actually returns a value (defined as HUGE in <math.h>) and no error. This is
probably supposed to stand for infinity, but I'd rather it be an error. If you
get weird values for invalid functions, the math routines could be to blame....
--**-----------
Graphing.
=========
After the little window pops up when you type "graf" from your cli, you can
see three options: "graph", "enter", and "quit". It is obvious which one exits
the program, so I won't dwell on it. The one to start with is "enter". This
option is used to enter up to 10 functions into the system.
Enter.
------
Initially, you get a window titled "Select" with 10 little boxes down the
left side. Graf wants you to select a function to enter (if blank) or change
(if not blank). When you click on one of them, a new window titled "Enter"
appears. This window is more interesting and has a lot of things to play
with. First, an explanation of the different gadgets.
The "okay" and "cancel" gadgets do just what you normally expect.
The "join" gadget toggles everytime you click it (try it if you don't believe
me). It is used for functions that define dots that have gaps between them.
When join is active, the dots are joined together as they are plotted giving a
smooth plot instead of something resembling bird droppings. Try functions with
and without join to see how it works. Each function has its own join flag, so
you can use it at your own descretion.
The funny little arrow gadget is very important. To the right of it are the
words "Y lo" (lower Y axis boundary), "Y hi" (upper Y axis boundary),
"X lo" (left X axis boundary), "X hi" (right X axis boundary), and some
numbers. Each triangle on the arrow gadget controls a graph boundary on both
the X and Y axes. You enter numbers representing boundaries in the string
gadget at the top of the window. Commonsense tells you which triangle controls
what. If you enter an illegal number, the screen will flash and no boundary
is changed. If a legal number is entered, the boundary is updated on the
screen. The square at the middle controls the entry of functions. When you
click on it, whatever is in the string gadget at the top gets checked and,
if valid, entered as a function to be graphed. If the string is invalid, the
screen blinks and nothing is changed. As much of the function as will fit is
displayed in the area just above the graph boundaries.
Right now, the cursor is on a string gadget and is waiting for you to
enter something. Using this, you can enter any function up to 80 characters in
length. At this point, you may be wondering how you can write a function
of x. It is not what you think. The parser will not accept anything but the
functions and symbols given above and one special symbol - "#". It is this
special symbol that represents x. An example of a function and its alternate
representation might be
F(x) = sin(x) + x == sin(#) + #
Try entering a few functions and changing the graph boundaries. When you're
finished, click on "okay".
Graph.
------
The next option to try is "graph". The Select window appears again, but this
time there are "okay" and "cancel" gadgets at the bottom. In this window,
you can select any number of the functions just by clicking on their select
boxes. Each box toggles as you click it so you'll know which ones you've
chosen. Click okay to begin graphing them or cancel to quit.
The evaluator is fairly quick, so you shouldn't have to wait long for your
graph. You will notice speed differences if you have a lot of trancendental
functions, though. After all graphs have been completed, a full screen
crosshair appears and you can move the mouse around to check the approximate
locations of different points on your function. I thought this might be a
useful little feature (ie. approximating "zeroes" of a function). The window
initially in the upper left tracks position. It can be moved, but you'll have
to click in the graphing window again to get your location displayed. To
exit back to the main menu, hit any key on the keyboard. And that's it.
Using the Calculator.
=====================
If you typed "graf calc" at the cli, you now have a "[1]" sitting at the left
of your cursor. This indicates the current line you're about to enter for
evaluation. Here the rules are simple:
- enter a function.
- If the function has "#" anywhere in it, you will enter a loop and will
be prompted to enter values for "#". The function is evaluated at
the given value and the result is displayed. To exit the loop,
enter "1\".
- If the function is valid, you get an answer.
- If the function is invalid, whether because of syntax or the rules of
math, you get an error.
- to exit, press <CTRL> \ to signal end-of-file.
Looping when a function contains "#" is useful for when you want evaluate one
function for many values. The same operators described above are valid in the
calculator. It's as simple as that.
Questions, Bitching, Etc.
=========================
Contact Bill Nickerson, 840493n@aucs on BitNet. I graduate in May, so don't
bother after then. I may pop up somwhere later on....
--**-----------
This has been a FreeWare Production.